<template>
    <div style="padding-left:5px;">
<!--        <pre>{{formData}}</pre>-->
        <el-row>
            <el-col align="left">
                <el-form>
                    <el-form-item label="数字：">
                        <el-input-number v-model="formData.num1" :min="1"  :step="1"
                        ></el-input-number>
                    </el-form-item>
                    <el-row>
                        <el-col align="center">
                            <el-button type="primary" @click="calc">计算因数</el-button>
                        </el-col>
                    </el-row>

                    <el-form-item label="结果：">
                        <p>如下所示：</p>
                        <div v-for="(result, index) in formData.resultArr" :key="'result_' + index" style="font-size: 30px;">
                            {{result.num1}} × {{result.num2}}
                        </div>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>

</template>

<script>
    /* eslint-disable */

    export default {
        name: 'divide1',
        data() {
            return {
                error: true,
                formData: {
                    num1: 24,
                    resultArr: [],
                },
            }
        },
        methods: {
            async calc() {
                let resultArr = []
                for (let i = 1; i <= parseInt(Math.sqrt(this.formData.num1)); i++) {
                    if (this.formData.num1 % i == 0) {
                        resultArr.push({
                            num1: i,
                            num2: this.formData.num1 / i,
                        })
                    }
                }
                this.formData.resultArr = resultArr
                this.$localStorage.set('factor1.formData', this.formData, 4 * 60 * 60 * 1000) // keep 1 day
            },
        },
        computed: {},
        mounted() {
            let formData = this.$localStorage.get('factor1.formData')
            if (formData) {
                this.formData = formData
            }
            this.calc()
        }
    };
</script>
<style>
</style>
